package org.proddevplm.business.flow;

import java.util.List;

import org.proddevplm.business.api.AController;
import org.proddevplm.business.flow.constants.FlowConstants;
import org.proddevplm.constants.ControllerConstants;
import org.proddevplm.constants.UserConstants;
import org.proddevplm.dao.data.Product;
import org.proddevplm.dao.data.Project;
import org.proddevplm.dao.data.RelationMatrix;
import org.proddevplm.dao.data.User;

public class FlowController extends AController {

	public Object execute(int command, Object data) {
		//return null;
		
		User user = (User)getSession().getAttribute(UserConstants.USER);
		
		switch (command) {
	
		case FlowConstants.NEW_PROJECT:			
			List<User> resultUsers = getDaoManager().getUserManager().getUsers();
			putOnState("userlist", resultUsers);
					
			List<String> resultRoles = getDaoManager().getRoleManager().getRoles();
			putOnState("roles", resultRoles);
			putOnState(ControllerConstants.NEXT_PAGE, "content/project/newProject.jsp");
			break;
		
		case FlowConstants.OPEN_PROJECT:
			List<Project> projects = getDaoManager().getProjectManager().getProjectByUserId(user.getId());
			removeFromSession("productId");
			putOnSession("projects", projects);
			putOnState(ControllerConstants.NEXT_PAGE, "content/project/openProject.jsp");
			break;
		
		case FlowConstants.MY_PROJECTS:
			List<Project> currentProjects = getDaoManager().getProjectManager().getProjectByUserId(user.getId());
			putOnSession("projects", currentProjects);
			
			List<RelationMatrix> relMatrix = getDaoManager().getProjectManager().getRelMatrixByUserId(user.getId());
			putOnSession("relMatrixUser", relMatrix);
			putOnState(ControllerConstants.NEXT_PAGE, "content/project/myProjects.jsp");
			break;
		
		case FlowConstants.PROJECTS_INDEX:
			if(user.getCategory().equals("devTeam")){
				putOnState(ControllerConstants.NEXT_PAGE, "content/project/projectIndex.jsp");
			}else{
				List<Product> allProducts = getDaoManager().getProductManager().getAllProducts();
				putOnSession("allProducts", allProducts);
				putOnState(ControllerConstants.NEXT_PAGE, "content/lifeCycleData/usePhase/consumerPage.jsp");
			}
			
			break;
		
		case FlowConstants.LOGIN_PAGE:
			putOnState(ControllerConstants.NEXT_PAGE, "startPage.jsp");
			break;
		}
	
	return null;
	}
	
}
